package zhuyouyong.agp8

import com.android.build.api.instrumentation.FramesComputationMode
import com.android.build.api.instrumentation.InstrumentationScope
import com.android.build.api.variant.AndroidComponentsExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import zhuyouyong.ObfuscateExtension

/**
 * Created by zhuyouyong@bm-intelligent.com on 2023/11/27.
 */
class ObfuscatePlugin : Plugin<Project> {
    override fun apply(target: Project) {
        target.extensions.create("obfuscate", ObfuscateExtension::class.java)
        target.extensions.getByType(
            AndroidComponentsExtension::class.java).onVariants { variant ->
            ObfuscateTransform.obfuscateExtension =
                target.extensions.getByType(ObfuscateExtension::class.java)
            variant.instrumentation.transformClassesWith(
                ObfuscateTransform::class.java, InstrumentationScope.ALL) {}
            variant.instrumentation.setAsmFramesComputationMode(
                FramesComputationMode.COMPUTE_FRAMES_FOR_INSTRUMENTED_METHODS)
        }
    }
}